package de.preamp.clients.java.utils;

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;

/**
 * A utility class defining various utility methods.
 * 
 * @author André Stannek
 * @version 2010-08-02
 */
public final class Tools
{
    /**
     * Returns a {@link java.awt.Rectangle} for use as parameter for the
     * {@link java.awt.Component#setBounds(Rectangle)} method. The use of this
     * rectangle will place the {@link java.awt.Component} in the middle of the
     * screen. For the computation the size of the {@link java.awt.Component} is
     * needed.
     * 
     * @param width
     *            width of the {@link java.awt.Component}
     * @param height
     *            height of the {@link java.awt.Component}
     * @return the {@link java.awt.Rectangle}
     */
    public static Rectangle getCenteredBounds(final int width, final int height)
    {
	final GraphicsEnvironment env =
		GraphicsEnvironment.getLocalGraphicsEnvironment();
	final GraphicsDevice graphicsDevice = env.getDefaultScreenDevice();
	final DisplayMode displayMode = graphicsDevice.getDisplayMode();

	final int xPos = (displayMode.getWidth() - width) / 2;
	final int yPos = (displayMode.getHeight() - height) / 2;

	return new Rectangle(xPos, yPos, width, height);
    }

    /**
     * masking utility class constructor.
     */
    private Tools()
    {
	super();
    }
}
